struct Node
{
    Node* son[26];//记录下一个字符的节点位置
    bool end = false;//这个节点是否为终点 
};
class Trie {
private:
    int find(string& str)
    {
        Node* cur =root;
        for(auto& e:str)
        {
            e-='a';
            if(cur->son[e] == nullptr)
            {
                return -1;//不存在这个字符串
            }
            cur = cur->son[e];
        }
        return cur->end;//
    }
public:
    Node* root = new Node();
    Trie() 
    {}
    
    void insert(string word) {
        Node* cur = root;
        for(auto& e:word)
        {
            e-='a';
            if(cur->son[e] == nullptr)
            {
                cur->son[e] = new Node();
            }
            cur = cur->son[e];
        } 
        cur->end = true;//代表这个节点是结束节点
    }
    
    bool search(string word) {
        if(find(word) == 1)
        {
            return true;
        }
        return false;
    }
    
    bool startsWith(string prefix) {
        if(find(prefix)!=-1)
        {
            return true;
        }
        return false;
    }
};

/**
 * Your Trie object will be instantiated and called as such:
 * Trie* obj = new Trie();
 * obj->insert(word);
 * bool param_2 = obj->search(word);
 * bool param_3 = obj->startsWith(prefix);
 */